package pattern.structural.flyweight.simple;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: chaoyang.ren
 * @date:Jul 13, 2017
 * @time:2:20:40 PM
 * @email:chaoyang.ren@foxmail.com
 * @version: 1.0
 */
public class FlyweightFactory {
	private static Map<String,FlyweightImpl> flyweights = new HashMap<String,FlyweightImpl>();

	private FlyweightFactory(String arg) {
		flyweights.put(arg, new FlyweightImpl());
	}

	public static Flyweight getFlyweight(String key) {
		if (flyweights.get(key) == null) {
			flyweights.put(key, new FlyweightImpl());
		}
		return (Flyweight) flyweights.get(key);
	}

	public static int getSize() {
		return flyweights.size();
	}
}
